PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Quit Handlers

AppleScript sends a stay-open script application a Quit command whenever the user chooses the Quit menu command or presses Command-Q while the application is active. If the script includes a Quit handler, the statements in the handler are run before the application quits.

A Quit handler can be used to set script properties, tell another application to do something, display a dialog box, or perform almost any other task. If the handler includes a continue quit statement, the script application's default quit behavior is invoked and it quits. If the Quit handler returns before it encounters a continue quit statement, the application doesn't quit.

For example, this handler checks with the user before allowing the application to quit:

on quit
    display dialog "Really quit?" ¬
        buttons {"No", "Quit"} default button "Quit"
    if the button returned of the result is "Quit" then
        continue quit
    end if
    -- Without the continue statement, the
    -- script application doesn't quit.
end quit

WARNING

If AppleScript doesn't encounter a continue quit statement while executing an on quit handler, it may seem impossible to quit the application. For example, if the handler gets an error before the continue quit statement, attempting to quit the application just produces an error alert. As a last resort, use the emergency Quit command: press Command-Shift-Q or hold down the Shift key and choose Quit from the File menu. This saves changes to script properties and quits immediately, bypassing the Quit handler.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)